package com.yiwyn.handle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

@Component
@Slf4j
public class ConsumerHandle {


    @Async
    public void testHandle() {
        log.info("执行线程:{}", Thread.currentThread().getName());
    }

    @Async
    public CompletableFuture<String> futureHandle() throws InterruptedException {
        TimeUnit.SECONDS.sleep(1);
        String name = (String) RequestContextHolder.getRequestAttributes().getAttribute("name", 0);
        System.out.println("线程中获取的name值" + name);
        return CompletableFuture.completedFuture("执行的线程" + Thread.currentThread().getName());
    }

}
